pred2 <- mnl_fd_ova(model = mod2,
data = df,
x = "respondent_gender_Male",
by = 1,
z = "fct_gender_Male",
z_values = c(0,1),
seed = 123123,
nsim = 1000, # faster
probs = c(0.025, 0.975))
pd2 <- pred2$plotdata_fd
pd2$ballotposition_new <- ifelse(is.na(as.numeric(pd2$ballotposition_new)),
"Deselected",
paste0("Position: ", pd2$ballotposition_new))
pd2$ballotposition_new <- factor(pd2$ballotposition_new,
levels = c(paste0("Position: ",1:6), "Deselected"))
# FIGURE 3
ggplot(data = pd2, aes(x = ballotposition_new,
y = mean,
ymin = lower,
ymax = upper)) +
geom_vline(aes(xintercept = ballotposition_new),
lty= 3,
color = "grey85") +
geom_hline(yintercept = 0, lty= 2) +
geom_pointrange(position = position_dodge(width = 0.5),
aes(color = ifelse(respondent_gender_Male == 1, "Male", "Female"),
shape = ifelse(respondent_gender_Male == 1, "Male", "Female"))) +
coord_flip() +
xlab("List Position") +
ylab("Effect of Male vs. Female Aspirant") +
theme_bw() +
scale_color_manual("Respondent's Gender", values = c("orange",
"steelblue")) +
scale_shape_manual("Respondent's Gender", values = c(15,16)) +
theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank()) +
theme(legend.position = "bottom")
ggsave(file = "gender_mlogit.pdf",
width = 8,
height = 4)
pd2pred <- pred2$plotdata
pd2pred$ballotposition_new <- ifelse(is.na(as.numeric(pd2pred$ballotposition_new)),
"Deselected",
paste0("Position: ", pd2pred$ballotposition_new))
pd2pred$ballotposition_new <- factor(pd2pred$ballotposition_new,
levels = c(paste0("Position: ",1:6), "Deselected"))
ggplot(data = pd2pred, aes(x = ifelse(respondent_gender_Male == 1, "Male", "Female"),
y = mean,
ymin = lower,
ymax = upper,
shape = ifelse(fct_gender_Male == 1, "Male", "Female"),
color = ifelse(fct_gender_Male == 1, "Male", "Female"))) +
geom_hline(yintercept = seq(0,0.4,by = 0.1),
lty= 3,
color = "grey85") +
geom_pointrange(size = .3, position = position_dodge(width = .5)) +
facet_wrap(~ ballotposition_new) +
xlab("Respondent's Gender") +
ylab("Probability") +
theme_bw() +
scale_shape_manual("Aspirant's Gender", values = c(15:16)) +
scale_color_manual("Aspirant's Gender", values = c("orange",
"steelblue")) +
theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank()) +
theme(legend.position = c(0.84,.13)) +
coord_flip()
ggsave(file = "gender_mlogit_pred.pdf",
width = 8,
height = 6)
# Model times supply
mod1 <- multinom(f1,
data = df,
Hess = TRUE)
pred1 <- mnl_fd_ova(model = mod1,
data = df,
x = "n_women",
by = 1,
z = "fct_gender_Male",
z_values = c(0,1),
seed = 123123,
nsim = 1000, # faster
probs = c(0.025, 0.975))
pd1 <- pred1$plotdata_fd
pd1$ballotposition_new <- ifelse(is.na(as.numeric(pd1$ballotposition_new)),
"Deselected",
paste0("Position: ", pd1$ballotposition_new))
pd1$ballotposition_new <- factor(pd1$ballotposition_new,
levels = c(paste0("Position: ",1:6), "Deselected"))
# FIGURE 2
ggplot(data = pd1, aes(x = n_women,
y = mean,
ymin = lower,
ymax = upper,
fill = ballotposition_new)) +
geom_hline(yintercept = seq(-.2,.2,by=.1),
lty= 3,
color = "grey85") +
geom_hline(yintercept = 0, lty= 2) +
geom_ribbon(alpha = .5) +
geom_line(color = "white") +
facet_wrap(~ ballotposition_new) +
xlab("# Female Aspirants at Stage 1") +
scale_x_continuous(breaks = 1:8) +
ylab("Effect of Male vs. Female Aspirant") +
theme_bw() +
scale_fill_manual("# Female Aspirtants", values = color_fill(7)) +
theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank()) +
theme(legend.position = "bottom") +
guides(fill = "none")
ggsave(file = "supply_mlogit.pdf",
width = 8,
height = 6)
pd1pred <- pred1$plotdata
pd1pred$ballotposition_new <- ifelse(is.na(as.numeric(pd1pred$ballotposition_new)),
"Deselected",
paste0("Position: ", pd1pred$ballotposition_new))
pd1pred$ballotposition_new <- factor(pd1pred$ballotposition_new,
levels = c(paste0("Position: ",1:6), "Deselected"))
ggplot(data = pd1pred, aes(x = n_women,
y = mean,
ymin = lower,
ymax = upper,
fill = ifelse(fct_gender_Male == 1, "Male", "Female"),
color = ifelse(fct_gender_Male == 1, "Male", "Female"))) +
geom_hline(yintercept = seq(0,0.4,by = 0.1),
lty= 3,
color = "grey85") +
geom_ribbon(alpha = .5, color = NA) +
geom_line(color = "white") +
facet_wrap(~ ballotposition_new) +
xlab("# Female Aspirants at Stage 1") +
scale_x_continuous(breaks = 1:8) +
ylab("Probability") +
theme_bw() +
scale_fill_manual("Aspirant's Gender", values = c("orange",
"steelblue")) +
scale_color_manual("Aspirant's Gender", values = c("orange",
"steelblue")) +
theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank()) +
theme(legend.position = c(0.84,.13))
ggsave(file = "supply_mlogit_pred.pdf",
width = 8,
height = 6)
# Model times leftright
mod3 <- multinom(f3,
data = df,
Hess = TRUE)
pred3 <- mnl_fd_ova(model = mod3,
data = df,
x = "lr",
by = 1,
z = "fct_gender_Male",
z_values = c(0,1),
seed = 123123,
nsim = 1000, # faster
probs = c(0.025, 0.975))
pd3 <- pred3$plotdata_fd
pd3$ballotposition_new <- ifelse(is.na(as.numeric(pd3$ballotposition_new)),
"Deselected",
paste0("Position: ", pd3$ballotposition_new))
pd3$ballotposition_new <- factor(pd3$ballotposition_new,
levels = c(paste0("Position: ",1:6), "Deselected"))
# FIGURE A22 (SECTION I)
ggplot(data = pd3, aes(x = lr,
y = mean,
ymin = lower,
ymax = upper,
fill = ballotposition_new)) +
geom_hline(yintercept = seq(-.2,.2,by=.1),
lty= 3,
color = "grey85") +
geom_hline(yintercept = 0, lty= 2) +
geom_ribbon(alpha = .5) +
geom_line(color = "white") +
facet_wrap(~ ballotposition_new) +
xlab("Left-Right") +
scale_x_continuous(breaks = 1:10) +
ylab("Effect of Male vs. Female Aspirant") +
theme_bw() +
scale_fill_manual("# Female Aspirtants", values = color_fill(7)) +
theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank()) +
theme(legend.position = "bottom") +
guides(fill = "none")
ggsave(file = "lr_mlogit.pdf",
width = 8,
height = 6)
pd3pred <- pred3$plotdata
pd3pred$ballotposition_new <- ifelse(is.na(as.numeric(pd3pred$ballotposition_new)),
"Deselected",
paste0("Position: ", pd3pred$ballotposition_new))
pd3pred$ballotposition_new <- factor(pd3pred$ballotposition_new,
levels = c(paste0("Position: ",1:6), "Deselected"))
ggplot(data = pd3pred, aes(x = lr,
y = mean,
ymin = lower,
ymax = upper,
fill = ifelse(fct_gender_Male == 1, "Male", "Female"),
color = ifelse(fct_gender_Male == 1, "Male", "Female"))) +
geom_hline(yintercept = seq(0,0.4,by = 0.1),
lty= 3,
color = "grey85") +
geom_ribbon(alpha = .5, color = NA) +
geom_line(color = "white") +
facet_wrap(~ ballotposition_new) +
xlab("Left-Right") +
scale_x_continuous(breaks = 1:10) +
ylab("Probability") +
theme_bw() +
scale_fill_manual("Aspirant's Gender", values = c("orange",
"steelblue")) +
scale_color_manual("Aspirant's Gender", values = c("orange",
"steelblue")) +
theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank()) +
theme(legend.position = c(0.84,.13))
ggsave(file = "lr_mlogit_pred.pdf",
width = 8,
height = 6)
# Model times lr party
mod4 <- multinom(f4,
data = df,
Hess = TRUE)
pred4 <- mnl_fd_ova(model = mod4,
data = df,
x = "rightwing_party",
by = 1,
z = "fct_gender_Male",
z_values = c(0,1),
seed = 123123,
nsim = 1000, # faster
probs = c(0.025, 0.975))
flist = list("fct_gender" = "Gender",
"fct_age" = "Age",
"fct_issue" = "Policy\nExpertise",
"fct_deviation" = "Deviation from\nparty",
"fct_experience" = "Incumbency",
"fct_personalvotes" = "Personal\nVotes",
"fct_otherlist" = "Dual\nCandidacy",
"fct_position" = "Intra-Party\nPosition")
df$region <- case_when(df$ebene1 == 1 ~ 1,
df$ebene2 == 1 ~ 2,
df$ebene3 == 1 ~ 3,
df$ebene4 == 1 ~ 0)
respondents %>%
group_by(party) %>%
count %>%
ungroup() %>%
mutate(percent = 100*n/sum(n)) %>%
xtable::xtable(digits = 1)
plot_amce_mm <- function(dv = ""){
df$depvar <- df[[dv]]
mm_base <- cregg::cj(depvar ~
fct_gender +
fct_age +
fct_issue +
fct_deviation + fct_personalvotes +
fct_experience +
fct_position +
fct_otherlist,
data = df,
id = ~ id,
estimate = "mm",
feature_labels = flist)
amce_base <- cregg::cj(depvar ~
fct_gender +
fct_age +
fct_issue +
fct_deviation + fct_personalvotes +
fct_experience +
fct_position +
fct_otherlist,
data = df,
id = ~ id,
estimate = "amce",
feature_labels = flist)
mm_base <- bind_rows(mm_base, amce_base)
if(grepl("pos", dv)){
mmline <- 1/9
} else{
mmline <- 1/3
}
hline_data <- data.frame("statistic" = c("AMCE", "MM"),
value = c(0,mmline))
mm_base$statistic <- ifelse(mm_base$statistic == "mm",
"MM", "AMCE")
ggplot(mm_base,
aes(x = level,
y = estimate,
color = feature)) +
coord_flip() +
geom_hline(data = hline_data, aes(yintercept = value), lty = 2) +
geom_point(size = 1.5,
position = position_dodge(width = 0.8)) +
geom_errorbar(aes(ymax = lower,
ymin = upper,
width = 0),
position = position_dodge(width = 0.8)) +
theme_bw() +
ggh4x::facet_nested(feature ~ statistic,
scales  ="free",
space = "free_y",
switch = "y") +
scale_x_discrete(position="top") +
theme(plot.background = element_rect(fill = 'white'),
axis.text.y = element_text(size = 9),
axis.text.x = element_text(angle = 0,
size = 9),
strip.text.y = element_text(angle = 90,
size = 9),
strip.text.y.left = element_text(angle = 0),
strip.background = element_rect(fill = 'white')) +
theme(plot.margin=unit(c(1,1,1,3),
"line"),
panel.border = element_rect(colour = "black"),
legend.position = "bottom") +
xlab(NULL) +
ylab(NULL) +
guides(color = "none")
ggsave(paste0("amce_mm_plot_",dv,".pdf"),
width = 8.5,
height = 8)
}
container <- map(c("deselected",paste0("pos",1:6)), plot_amce_mm)
dv = "deselected"
df$deselected
df$depvar <- df[[dv]]
mm_base <- cregg::cj(depvar ~
fct_gender +
fct_age +
fct_issue +
fct_deviation + fct_personalvotes +
fct_experience +
fct_position +
fct_otherlist,
data = df,
id = ~ id,
estimate = "mm",
feature_labels = flist)
amce_base <- cregg::cj(depvar ~
fct_gender +
fct_age +
fct_issue +
fct_deviation + fct_personalvotes +
fct_experience +
fct_position +
fct_otherlist,
data = df,
id = ~ id,
estimate = "amce",
feature_labels = flist)
mm_base <- bind_rows(mm_base, amce_base)
if(grepl("pos", dv)){
mmline <- 1/9
} else{
mmline <- 1/3
}
hline_data <- data.frame("statistic" = c("AMCE", "MM"),
value = c(0,mmline))
mm_base$statistic <- ifelse(mm_base$statistic == "mm",
"MM", "AMCE")
ggplot(mm_base,
aes(x = level,
y = estimate,
color = feature)) +
coord_flip() +
geom_hline(data = hline_data, aes(yintercept = value), lty = 2) +
geom_point(size = 1.5,
position = position_dodge(width = 0.8)) +
geom_errorbar(aes(ymax = lower,
ymin = upper,
width = 0),
position = position_dodge(width = 0.8)) +
theme_bw() +
ggh4x::facet_nested(feature ~ statistic,
scales  ="free",
space = "free_y",
switch = "y") +
scale_x_discrete(position="top") +
theme(plot.background = element_rect(fill = 'white'),
axis.text.y = element_text(size = 9),
axis.text.x = element_text(angle = 0,
size = 9),
strip.text.y = element_text(angle = 90,
size = 9),
strip.text.y.left = element_text(angle = 0),
strip.background = element_rect(fill = 'white')) +
theme(plot.margin=unit(c(1,1,1,3),
"line"),
panel.border = element_rect(colour = "black"),
legend.position = "bottom") +
xlab(NULL) +
ylab(NULL) +
guides(color = "none")
flist = list("fct_gender" = "Gender",
"fct_age" = "Age",
"fct_issue" = "Policy\nExpertise",
"fct_deviation" = "Deviation from\nparty",
"fct_experience" = "Incumbency",
"fct_personalvotes" = "Personal\nVotes",
"fct_otherlist" = "Dual\nCandidacy",
"fct_position" = "Intra-Party\nPosition")
df$pos1 <- ifelse(as.numeric(df$ballotposition) == 1, 1, 0)
df$pos1[is.na(df$pos1)] <- 0
df$pos2 <- ifelse(as.numeric(df$ballotposition) == 2, 1, 0)
df$pos2[is.na(df$pos2)] <- 0
df$pos3 <- ifelse(as.numeric(df$ballotposition) == 3, 1, 0)
df$pos3[is.na(df$pos3)] <- 0
df$pos4 <- ifelse(as.numeric(df$ballotposition) == 4, 1, 0)
df$pos4[is.na(df$pos4)] <- 0
df$pos5 <- ifelse(as.numeric(df$ballotposition) == 5, 1, 0)
df$pos5[is.na(df$pos5)] <- 0
df$pos6 <- ifelse(as.numeric(df$ballotposition) == 6, 1, 0)
df$pos6[is.na(df$pos6)] <- 0
df$region <- case_when(df$ebene1 == 1 ~ 1,
df$ebene2 == 1 ~ 2,
df$ebene3 == 1 ~ 3,
df$ebene4 == 1 ~ 0)
####################################
# Descriptive Table (part of table 1)
####################################
respondents %>%
group_by(party) %>%
count %>%
ungroup() %>%
mutate(percent = 100*n/sum(n)) %>%
xtable::xtable(digits = 1)
####################################
# Basic AMCE/MM Plots (Appendix K)
####################################
df$deselected
plot_amce_mm <- function(dv = ""){
df$depvar <- df[[dv]]
mm_base <- cregg::cj(depvar ~
fct_gender +
fct_age +
fct_issue +
fct_deviation + fct_personalvotes +
fct_experience +
fct_position +
fct_otherlist,
data = df,
id = ~ id,
estimate = "mm",
feature_labels = flist)
amce_base <- cregg::cj(depvar ~
fct_gender +
fct_age +
fct_issue +
fct_deviation + fct_personalvotes +
fct_experience +
fct_position +
fct_otherlist,
data = df,
id = ~ id,
estimate = "amce",
feature_labels = flist)
mm_base <- bind_rows(mm_base, amce_base)
if(grepl("pos", dv)){
mmline <- 1/9
} else{
mmline <- 1/3
}
hline_data <- data.frame("statistic" = c("AMCE", "MM"),
value = c(0,mmline))
mm_base$statistic <- ifelse(mm_base$statistic == "mm",
"MM", "AMCE")
ggplot(mm_base,
aes(x = level,
y = estimate,
color = feature)) +
coord_flip() +
geom_hline(data = hline_data, aes(yintercept = value), lty = 2) +
geom_point(size = 1.5,
position = position_dodge(width = 0.8)) +
geom_errorbar(aes(ymax = lower,
ymin = upper,
width = 0),
position = position_dodge(width = 0.8)) +
theme_bw() +
ggh4x::facet_nested(feature ~ statistic,
scales  ="free",
space = "free_y",
switch = "y") +
scale_x_discrete(position="top") +
theme(plot.background = element_rect(fill = 'white'),
axis.text.y = element_text(size = 9),
axis.text.x = element_text(angle = 0,
size = 9),
strip.text.y = element_text(angle = 90,
size = 9),
strip.text.y.left = element_text(angle = 0),
strip.background = element_rect(fill = 'white')) +
theme(plot.margin=unit(c(1,1,1,3),
"line"),
panel.border = element_rect(colour = "black"),
legend.position = "bottom") +
xlab(NULL) +
ylab(NULL) +
guides(color = "none")
ggsave(paste0("amce_mm_plot_",dv,".pdf"),
width = 8.5,
height = 8)
}
container <- map(c("deselected",paste0("pos",1:6)), plot_amce_mm)
container
stargazer(as.data.frame(bp_index))
stargazer::stargazer(as.data.frame(bp_index))
?stargazer::stargazer
